package com.zw.service.impl;

import java.util.List;

import javax.swing.plaf.basic.BasicInternalFrameTitlePane.IconifyAction;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zw.dao.CommodityMapper;
import com.zw.entity.Commodity;
import com.zw.entity.CommodityExample;
import com.zw.redisConfig.RedisUtil;
import com.zw.service.CommodityService;

@Service
public class CommodityServiceImpl implements CommodityService{

	@Autowired
	private CommodityMapper commodityMapper;
	
	@Cacheable(value="commodityCacheByTypeId")
	@Override
	public List<Commodity> selectCommodity(int tepyId) {
			CommodityExample example=new CommodityExample();
			example.or().andCommoditytypeidEqualTo(tepyId);
			List<Commodity> list=commodityMapper.selectByExample(example);
		return list;
	}

	@Cacheable(value="commodityCacheById")
	@Override
	public Commodity select(int id) {
		CommodityExample cExample=new CommodityExample();
		cExample.or().andCommodityidEqualTo(id);
		Commodity c=commodityMapper.selectCommodity(cExample);
		return c;
	}

	@Override
	@Transactional
	public int insertCommodity(List<Commodity> list) {
		try {
			for (Commodity commodity : list) {
				commodityMapper.insert(commodity);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
		return 1;
	}

	@Override
	public List<Commodity> selectAll() {
		CommodityExample cExample=new CommodityExample();
		return commodityMapper.selectByExample(cExample);
	}
	
	
}
